using AirlineBookingSystem.BuildingBlocks.Common;
using AirlineBookingSystem.Flight.Application.Handlers;
using AirlineBookingSystem.Flight.Core.Repositories;
using AirlineBookingSystem.Flight.Infrastructure.Data;
using AirlineBookingSystem.Flight.Infrastructure.Repositories;
using MassTransit;
using Microsoft.Data.SqlClient;
using System.Data;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Register MediatR
var assemblies = new Assembly[]
    {
        Assembly.GetExecutingAssembly(),
        typeof(GetAllFlightsHandler).Assembly,
        typeof(CreateFlightsHandler).Assembly,
        typeof(DeleteFlightHandler).Assembly
    };
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(assemblies));


// Application Services
builder.Services.AddScoped<IFlightContext, FlightContext>();
builder.Services.AddScoped<IFlightRepository, FlightRepository>();
builder.Services.AddScoped<IFlightRepository, FlightDbRepository>();


// Add Sql Connection


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
